"""
:Author: Sven Walter <sven.walter@wltr.eu>
:Since: 10.03.2011
"""

from django.shortcuts import redirect
from django.shortcuts import render_to_response
from django.template import RequestContext
from django.template import loader

redirect = redirect

__all__ = ['easy_form', 'response', 'render', 'permanent_redirect', 'redirect']

def easy_form( request, Form, *args, **kwargs ):
    if request.method == 'POST':
        form = Form( request.POST, request.FILES, *args, **kwargs )
        if form.is_valid():
            if hasattr(form, 'save'):
                form.save()
            return ( form, True )
    else:
        form = Form( *args, **kwargs )
    
    return ( form, False )




def response(request, template, **kwargs):
    return render_to_response(template, kwargs,
                              context_instance=RequestContext(request))  

def render(tpl, **kwargs):
        return loader.render_to_string(tpl, kwargs)

def permanent_redirect(*args, **kwargs):
    kwargs['permanent'] = True
    return redirect(*args, **kwargs)